﻿Public Class Ccobranza

    Public Shared Function ActualizarMontos(ByVal descEmpresa As String, _
                                          ByVal pCobranza As EseparacionVentaDetallePagos, _
                                          ByVal pDistribuir As List(Of EseparacionVentaDetallePagos)) As Boolean
        Dim resultado As Boolean = False

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                RseparacionVentaDetallePagos.EliminarDistribuir(descEmpresa, pCobranza)

                Dim resultadoSeparacionPagos As Boolean = False
                For Each pd As EseparacionVentaDetallePagos In pDistribuir
                    pd.idSeparacionVenta = pDistribuir.ElementAt(0).idSeparacionVenta
                    resultadoSeparacionPagos = RseparacionVentaDetallePagos.Añadir(descEmpresa, pd)
                Next

                If resultadoSeparacionPagos Then resultado = True

                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return resultado
    End Function

    Public Shared Function distribuirPagos(ByVal descEmpresa As String, _
                                          ByVal pCobranza As EseparacionVentaDetallePagos, _
                                          ByVal pDistribuir As List(Of EseparacionVentaDetallePagos)) As Boolean
        Dim resultado As Boolean = False

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                RseparacionVentaDetallePagos.EliminarDistribuir(descEmpresa, pCobranza)

                Dim resultadoSeparacionPagos As Boolean = False
                For Each pd As EseparacionVentaDetallePagos In pDistribuir
                    pd.idSeparacionVenta = pDistribuir.ElementAt(0).idSeparacionVenta
                    resultadoSeparacionPagos = RseparacionVentaDetallePagos.Añadir(descEmpresa, pd)
                Next

                If resultadoSeparacionPagos Then resultado = True

                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return resultado
    End Function

End Class
